//
//  TTZuanshiScopeView.m
//  TaoTuo
//
//  Created by LG on 2020/10/15.
//  Copyright © 2020 刘广. All rights reserved.
//

#import "TTZuanshiScopeView.h"

@interface TTZuanshiScopeView()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) LLTagView *tagView;
@property (nonatomic, strong) LLTagConfig *config;

@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) void(^selectBlock)(NSArray *selectArray);

@end

@implementation TTZuanshiScopeView

- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title datasArray:(NSArray *)datasArray selectBlock:(void(^)(NSArray *selectArray))selectBlock config:(nullable LLTagConfig *)config
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.title = title;
        self.dataArray = datasArray;
        self.selectBlock = selectBlock;
        self.config = config;
        
        [self setupSubviews];
        
    }
    return self;
}

- (void)setDataArray:(NSArray *)dataArray
{
    _dataArray = dataArray;
    
    [self.tagView setupDatasArray:dataArray];
}

- (void)setAllowMutiSelect:(BOOL)allowMutiSelect
{
    _allowMutiSelect = allowMutiSelect;
    if (allowMutiSelect) {
        _canCancelSelect = YES;
    }
    self.tagView.allowMutiSelect = allowMutiSelect;
}

- (void)setCanCancelSelect:(BOOL)canCancelSelect
{
    if (self.allowMutiSelect) {
        _canCancelSelect = YES;
        self.tagView.canCancelSelect = YES;
        return;
    }
    _canCancelSelect = canCancelSelect;
    self.tagView.canCancelSelect = canCancelSelect;
}

- (void)resetView
{
    [self.tagView resetView];
}

- (void)setSelectIndex:(NSInteger)index
{
    [self.tagView setDefaultSelectIndex:index];
}

- (void)setSelectIndexs:(NSArray *)indexs
{
    [self.tagView setDefaultSelectIndexs:indexs];
}

- (void)setupSubviews
{
    CGFloat titleLabelH = self.title.length > 0 ? 30 : 0;
    _titleLabel = [UILabel labelWithTitle:self.title color:UIColorHex(#333333) font:[UIFont boldSystemFontOfSize:15]];
    _titleLabel.frame = CGRectMake(10, 0, self.width, titleLabelH);
    [self addSubview:_titleLabel];
    
    _tagView = [[LLTagView alloc] initWithFrame:CGRectMake(0, _titleLabel.bottom + 5, self.width, 40) dataArray:self.dataArray selectItems:self.selectBlock config:self.config];
    [self addSubview:_tagView];
    
    self.height = _titleLabel.height + _tagView.height + 10;
}

@end
